package com.lql.common.util;

import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import lombok.extern.log4j.Log4j2;

import java.util.Map;

/**
 * @Title:
 * @Description:
 * @Author: longge
 * @Date: 2020/6/19
 * @Version: V1.0
 */
@Log4j2
public class NotifyUtil {

    public static String sendPost(Map paramMap, String notifyUrl) {

        log.info("开始发送异步通知:{}", notifyUrl);
        log.info("通知参数：{}", paramMap.toString());
        //链式构建请求
        String result = HttpRequest.post(notifyUrl)
                .header(Header.USER_AGENT, "Hutool http")//头信息，多个头信息多次调用此方法即可
                .form(paramMap)//表单内容
                .timeout(60000)//超时，毫秒
                .execute().body();
        log.info("返回信息:{}", result);
        return result;
    }


    public static String sendGet(Map paramMap, String notifyUrl) {

        log.info("开始发送异步通知:{}", notifyUrl);
        log.info("通知参数：{}", paramMap.toString());
        //链式构建请求
        String result = HttpRequest.get(notifyUrl)
                .header(Header.USER_AGENT, "Hutool http")//头信息，多个头信息多次调用此方法即可
                .form(paramMap)//表单内容
                .timeout(5000)//超时，毫秒
                .execute().body();
        log.info("返回信息:{}", result);
        return result;
    }
}
